<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="text-box" size="20" value="Mozilla" />
    <button onclick="selectText()">Select text</button>
    <script>
      function selectText() {
        const input = document.getElementById('text-box')
        input.focus()
        // input.setSelectionRange(2, 5)
        // input.setSelectionRange(0, -1)
        input.setSelectionRange(-1, -1)
      }
    </script>
  </body>
</html>
